package com.twq.useage

import java.util

/**
 * Created by tangweiqun on 2017/11/18.
 */
object JavaConversionsTest {
  def main(args: Array[String]): Unit = {
    import scala.collection.JavaConversions.bufferAsJavaList
    //1、scala.collection.mutable.ArrayBuffer => java.util.List
    // ArrayBuffer的父类是Buffer
    val buffer = scala.collection.mutable.ArrayBuffer(2, 3, 5)
    method1(buffer)
    println(buffer)

    //2、java.util.HashSet => scala.collection.mutable.Set
    import scala.collection.JavaConversions.asScalaSet
    val jset = new util.HashSet[Int]()
    method2(jset)
    println(jset)
  }

  def method1(jlist: java.util.List[Int]): Unit = {
    jlist.add(2)
  }

  def method2(set: scala.collection.mutable.Set[Int]): Unit = {
    set += 2
  }
}
